//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef TRACTORDECIDER_H_
#define TRACTORDECIDER_H_

#include <BaseDecider.h>
#include <AirFrame_m.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include "tractorTraceReader.h"

class tractorDecider: public BaseDecider {

public:
    std::string directoryPath;
    std::vector<std::string> fileList;
    std::vector<int> idFileList;
    tractorTraceReader* traceReader;
    int foundMessages;
    int notFoundMessages;
    int interferences;

public:
    tractorDecider(DeciderToPhyInterface* phy,
              double sensitivity,
              int myIndex,
              bool debug,
              const char* dirPth,
              const char* fList,
              const char* idFList):
        BaseDecider(phy, sensitivity, myIndex, debug)
    {
        directoryPath = std::string(dirPth);
        convertFileList(fList);
        convertFileIds(idFList);
        traceReader = new tractorTraceReader(directoryPath, fileList, idFileList);
        foundMessages = 0;
        notFoundMessages = 0;
        interferences = 0;
    }

protected:
    virtual simtime_t processNewSignal(AirFrame* frame);
    virtual simtime_t processSignalHeader(AirFrame* frame);
    virtual simtime_t processSignalEnd(AirFrame* frame);
    bool checkFree();
    void checkCodeTraceReader(int code, AirFrame* frame);
    int getIdFromName(const char* name);
    /* utilities to convert string representation in lists*/
    void convertFileList(const char* fList);
    void convertFileIds(const char* idFList);
    void finish();
};

#endif /* TRACTORDECIDER_H_ */
